﻿using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;

namespace wow_api
{
    public class Armory
    {
        public Character GetCharacter(string realm, string characterName)
        {
            var url = string.Format("http://us.battle.net/api/wow/character/{0}/{1}?fields=stats,items", realm, characterName);
            var request = WebRequest.Create(url);
            try
            {
                var ws = request.GetResponse();
                var stream = ws.GetResponseStream();
                var serializer = new DataContractJsonSerializer(typeof (Character));
                return (Character) serializer.ReadObject(stream);
            }
            catch (WebException)
            {
                
            }
            return null;
        }

        public Realms GetRealms()
        {
            var request = WebRequest.Create("http://us.battle.net/api/wow/realm/status");
            var ws = request.GetResponse();
            var stream = ws.GetResponseStream();
            var serializer = new DataContractJsonSerializer(typeof(Realms));
            return (Realms)serializer.ReadObject(stream);
        }

        public Classes GetClasses()
        {
            var url = "http://us.battle.net//api/wow/data/character/classes";
            var request = WebRequest.Create(url);
            try
            {
                var ws = request.GetResponse();
                var stream = ws.GetResponseStream();
                var serializer = new DataContractJsonSerializer(typeof(Classes));
                return (Classes)serializer.ReadObject(stream);
            }
            catch (WebException)
            {
                
            }
            return null;            
        }        
    }
}
